
//
// Copyright 2009 Arne Halvorsen (arne.halvorsen@gmail.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Project page: http://code.google.com/p/webfg/

//
// 091201 - aha42 - Created.
// 091213 - aha42 - init now also accepts ServletContext.
//

package org.aha.webfg;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aha.mf4j.FlickrSession;

/**
 * <p>
 *   Interface for object 
 *   {@link WebfgServlet} delegates request handling to. 
 * </p>
 * @author Arne Halvorsen (aha42)
 */
public interface WebfgPageCreator 
{
  /**
   * <p>
   *   Initializes before asked to handle any requests.
   * </p>
   * @param fs {@link FlickrSession} to communicate with Flickr with.
   * @param sc {@link ServletContext} exists in.
   */
  void init(FlickrSession fs, ServletContext sc);
  
  /**
   * <p>
   *   Handles request where parameter {@code where} is {@code info}.
   * </p>
   * @param req  HTTP Request.
   * @param resp HTTP Response.
   * @throws IOException If fails.
   */
  void handleInfoReq(HttpServletRequest req, HttpServletResponse resp) 
    throws IOException;
  
  /**
   * <p>
   *   Handles request with no parameters.
   * </p>
   * @param req  HTTP Request.
   * @param resp HTTP Response.
   * @throws IOException If fails.
   */
  void handleDefaultReq(HttpServletRequest req, HttpServletResponse resp) 
    throws IOException;
  
  /**
   * <p>
   *  Handles request where parameter {@code where} is {@code front}.
   * </p>
   * @param req  HTTP Request.
   * @param resp HTTP Response.
   * @throws IOException If fails.
   */
  void handleFrontReq(HttpServletRequest req, HttpServletResponse resp) 
    throws IOException;

  /**
   * <p>
   *   Handles request where parameter {@code where} is {@code piece}.
   * </p>
   * @param req  HTTP Request.
   * @param resp HTTP Response.
   * @throws IOException If fails.
   */
  void handlePieceReq(HttpServletRequest req, HttpServletResponse resp) 
    throws IOException;

  /**
   * <p>
   *   Handles unknown request.
   * </p>
   * @param req  HTTP Request.
   * @param resp HTTP Response.
   * @throws IOException If fails.
   */
  void handleUnknownReq(HttpServletRequest req, HttpServletResponse resp) 
    throws IOException;
  
  /**
   * <p>
   *   Handles response to client when something did g wrong.
   * </p>
   * @param t    Error.
   * @param resp
   * @param resp HTTP Response.
   * @throws IOException If fails.
   */
  void handleError(Throwable t, HttpServletResponse resp) throws IOException;
  
}
